package com.example.takeaway.api;

import com.example.takeaway.common.R;
import com.example.takeaway.model.dto.ShopLoginDTO;
import com.example.takeaway.model.vo.UserTokenVO;
import com.example.takeaway.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author 邢晨旭
 * @since 2023-10-12
 */
@RestController
@RequestMapping("/user")
public class UserApi {

    @Resource
    UserService userService;

    @GetMapping("/login/code")
    public R<Void> sendCode(@RequestParam String email) {
        userService.sendCode(email);
        return R.ok();
    }

    @PostMapping("/login/code")
    public R<UserTokenVO> loginByCode(@RequestParam String email, @RequestParam String code) {
        return R.ok(userService.loginByCode(email, code));
    }

    @PostMapping("/login")
    public R<UserTokenVO> loginByUsernameAndPassword(@RequestBody ShopLoginDTO param) {
        return R.ok(userService.loginByUsernameAndPassword(param));
    }

}
